package cn.kgc.springcloud.controller;

import cn.kgc.springcloud.commons.ResponseResult;
import cn.kgc.springcloud.entity.Group;
import cn.kgc.springcloud.service.GroupService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Date;

/**
 * @author 课工场
 * @date 2024/5/9
 * @description
 */
@RestController
@RequestMapping("group")
public class GroupController {

    @Resource
    private GroupService groupService;
    // 小组列表
    @GetMapping
    public ResponseResult groupList(){
       return groupService.groupList();
    }


    // 根据id获取小组信息
    @GetMapping("{id}")
    public Group getOneGroup(@PathVariable("id") Integer id){
        return groupService.getById(id);
    }

    // 添加小组
    @PostMapping
    public ResponseResult addGroup(@RequestBody Group group){
        group.setCreatedate(new Date());
        groupService.save(group);
        return ResponseResult.success().data(group).message("添加成功");
    }
}
